﻿#region 命名空间
using System.Xml.Serialization;
using System.Windows.Media;
#endregion

namespace ContentFactory
{
    /// <summary>
    /// 素材对象。
    /// </summary>
    public abstract class ContentObject : ViewObject
    {
        #region 事件

        /// <summary>
        /// 当素材对象名称更改后触发。
        /// </summary>
        public event NamingEventHandler NameChanged;
        void OnNameChanged(string oldName)
        {
            if (NameChanged != null)
                NameChanged(this, oldName, _name);
        }

        #endregion

        #region 属性

        /// <summary>
        /// 名称。
        /// </summary>
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    string oldName = _name;
                    _name = value;
                    this.OnNameChanged(oldName);
                    this.Raise("Name");
                }
            }
        }
        string _name;

        /// <summary>
        /// 图标。
        /// </summary>
        [XmlIgnore]
        public ImageSource Icon
        {
            get { return _icon; }
            set
            {
                if (_icon != value)
                {
                    _icon = value;
                    this.Raise("Icon");
                }
            }
        }
        ImageSource _icon;

        /// <summary>
        /// 项目对象。
        /// </summary>
        [XmlIgnore]
        public Project Project
        {
            get { return _project; }
            internal set { _project = value; }
        }
        Project _project;

        /// <summary>
        /// 上一级素材目录。
        /// </summary>
        [XmlIgnore]
        public ContentDirectory Parent
        {
            get { return _parent; }
            internal set { _parent = value; }
        }
        ContentDirectory _parent;

        #endregion

        #region 初始化

        /// <summary>
        /// 初始化。
        /// </summary>
        internal ContentObject()
        {
        }

        #endregion
    }
}
